var arr = [3, 1, 3, 6, 7, 2, 4, 8];

// iterating through the array's elements to the last but one
for (var i = 0; i < arr.length - 1; i++)
{
    var isCurrentLowestChanged = false;
    var indexOfCurrentLowest = i;

    // finding the lowest element in the array starting from the next after arr[i]
    for (var j = i + 1; j < arr.length; j++)
    {
        if (arr[j] < arr[indexOfCurrentLowest])
        {
            indexOfCurrentLowest = j;
            isCurrentLowestChanged = true;
        }
    }

    // swap the current arr[i] with the lowest found in the array
    if (isCurrentLowestChanged === true)
    {
        arr[i] += arr[indexOfCurrentLowest];
        arr[indexOfCurrentLowest] = (arr[i] - arr[indexOfCurrentLowest]);
        arr[i] -= arr[indexOfCurrentLowest];
    }
}

console.log(arr);